package org.wanho.manager.servlet;

import org.wanho.manager.entity.User;
import org.wanho.manager.service.UserService;
import org.wanho.manager.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Author：汤小洋
 * Date：2023-04-23 14:34
 * Description：<描述>
 */
@WebServlet("/managerIndex")
public class UserServlet extends HttpServlet {

    private UserService userService = new UserServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<User> users = userService.findAll();

        // 将数据存储到request作用域中
        req.setAttribute("users", users);
        // 转发到页面
        req.getRequestDispatcher("/manager/index.jsp").forward(req,resp);

    }
}
